package com.smartwebee.android.blespp.hospital.fragment;


import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.smartwebee.android.blespp.R;
import com.smartwebee.android.blespp.databinding.FragmentMineBinding;
import com.smartwebee.android.blespp.hospital.MyDevicesActivity;
import com.smartwebee.android.blespp.hospital.MyPlansActivity;
import com.smartwebee.android.blespp.hospital.MyTestsActivity;
import com.smartwebee.android.blespp.hospital.account.LoginActivity;
import com.smartwebee.android.blespp.utils.Utils;

/**
 * A simple {@link Fragment} subclass.
 */
public class MineFragment extends Fragment {

    private FragmentMineBinding binding;

    public MineFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        binding = DataBindingUtil.inflate(inflater, R.layout.fragment_mine, container, false);
        return binding.getRoot();
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        binding.tvSn.setText(Utils.registerResp.getData().getSn());
        binding.tvDoctor.setText(Utils.registerResp.getData().getDoctor());
        binding.clayoutPlan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(getActivity(), MyPlansActivity.class));
            }
        });
        binding.clayoutSurvey.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(getActivity(), MyTestsActivity.class));
            }
        });
        binding.clayoutDevice.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(getActivity(), MyDevicesActivity.class));
            }
        });
        binding.btnLogout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Utils.saveData(getActivity(), Utils.PWD, "");
                startActivity(new Intent(getActivity(), LoginActivity.class));
                getActivity().finish();
            }
        });
    }
}
